package com.ymatou.c2cliveindexer.service;

import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONObject;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.ymatou.c2cliveindexer.parameter.LiveSearchReturnBean;
import com.ymt.base.YmatouBaseCall;
import com.ymttest.utils.EnvSetup;
/**
 * 
 * 
 * 
 * 该文件已废弃
 * 
 * 
 * 
 * 
 * */
/**
 * c2clive搜索首页列表接口Call FreeMaker Template自动生成代码
 */
public class LiveSearchCall extends YmatouBaseCall {
	private static String opurl = "search/c2c";

	public LiveSearchCall() {
		super(EnvSetup.getSystemUrl("api_c2clivebizer"), opurl, "GET", "PARAM");
	}

	@Override
	public void addDefHeader() {
		client.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp");
		// client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}

	/**
	 * 获取total
	 * 
	 * @return
	 */
	public int getTotal() {
		int total = 0;
		try {
			total = Integer.valueOf(new JSONObject(getReturnData()).getString("total"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return total;
	}

	/**
	 * 获取status
	 * 
	 * @return
	 */
	public String getStatus() {
		String status = null;
		try {
			status = new JSONObject(getReturnData()).getString("status");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return status;
	}

	/**
	 * 获取hits列表
	 * 
	 * @return
	 */
	public ArrayList<LiveSearchReturnBean> getHitsList() {
		ArrayList<LiveSearchReturnBean> list = new ArrayList<LiveSearchReturnBean>();
		try {
			String rd = new JSONObject(getReturnData()).getString("hits");
			Gson gson = new Gson();
			list = gson.fromJson(rd, new TypeToken<ArrayList<LiveSearchReturnBean>>() {
			}.getType());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}

	/**
	 * 获取hits列表
	 * 
	 * @return
	 */
	public ArrayList<HashMap<String, String>> getHitsList2() {
		ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
		try {
			String rd = new JSONObject(getReturnData()).getString("hits");
			Gson gson = new Gson();
			list = gson.fromJson(rd, new TypeToken<ArrayList<HashMap<String, String>>>() {
			}.getType());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
}